AOP = {
	around:function(pointcut,before,after,namespaces){
		var args = arguments;
		console.log(args);
		AOP._weaving(pointcut,function(proxy){
			if(typeof args[1] == "function"){
				args[1].apply(this,proxy.arguments);
			}
			var ret = AOP.execute(proxy);
			if(typeof args[2] == "function"){
				args[2].apply(this,proxy.arguments);
			}
			return ret;
		},namespaces);
	},
	before:function(pointcut,advice,namespaces){
		AOP._weaving(pointcut,function(proxy){
			if(typeof advice == "function"){
				advice.apply(this,proxy.arguments);
			}
			return AOP.execute(proxy);
		},namespaces);
	},
	after:function(pointcut,advice,namespaces){
		AOP._weaving(pointcut,function(proxy){
			var ret = AOP.execute(proxy);
			if(typeof advice == "function"){
				advice.apply(this,proxy.arguments);
			}
			return ret;
		},namespaces);
	},
	execute:function(target){
		//执行原方法(target.fn为原方法,target.arguments为程序调用方法是的参数)
		return target.fn.apply(this,target.arguments);
	},
	_weaving:function(pointcut,advice,namespaces){
		//确定作用域 默认为window对象
		if(namespaces == undefined || namespaces.length == 0){
			namespaces = [(function(){return this}).call()];
		}
		//遍历作用域
		for(var i in namespaces){
			var ns = namespaces[i];
			//遍历作用域的属性
			for(var member in ns){
				//找到匹配pointcut的方法属性
				if(typeof ns[member] == "function" && member.match(pointcut)){
					//改变匹配方法属性(代理方法)
					(function(fn,fnName,ns){
						ns[member] = function(){
							return advice.call(ns,{fn:fn,fnName:fnName,arguments:arguments});
						};
					})(ns[member],member,ns)
				}
			}
		}
	}
}